//package com.lu.sb210222client.heart;
//
//import io.netty.bootstrap.Bootstrap;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.EventLoopGroup;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.SocketChannel;
//import io.netty.channel.socket.nio.NioSocketChannel;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//
//@Component
//public class HeartbeatClient {
//    private final static Logger LOGGER = LoggerFactory.getLogger(HeartbeatClient.class);
//    private EventLoopGroup group = new NioEventLoopGroup();//(1)
//    @Value("${socket.port}")
//    private int nettyPort;
//    @Value("${socket.ip}")
//    private String host;
//
//    private SocketChannel socketChannel;
//
//    @PostConstruct
//    public void start() throws InterruptedException {
//        Bootstrap bootstrap = new Bootstrap();//(2)
//        /**
//         * NioSocketChannel用于创建客户端通道，而不是NioServerSocketChannel。
//         * 请注意，我们不像在ServerBootstrap中那样使用childOption()，因为客户端SocketChannel没有父服务器。
//         */
//        bootstrap.group(group)
//        .channel(NioSocketChannel.class)//(3)
//        .handler(new CustomerHandleInitializer());//(4)
//        /**
//         * 启动客户端
//         * 我们应该调用connect()方法而不是bind()方法。
//         */
//        ChannelFuture future = bootstrap.connect(host, nettyPort).sync();//(5)
//        if (future.isSuccess()) {
//            LOGGER.info("启动 Netty 成功");
//        }
//
//        socketChannel = (SocketChannel) future.channel();
//
//    }
//
//}
